package net.wanho.shop.service.impl;

import net.wanho.shop.po.Express;
import net.wanho.shop.mapper.ExpressMapper;
import net.wanho.shop.service.ExpressService;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 快递表 服务实现类
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class ExpressServiceImpl implements ExpressService {

    private final ExpressMapper expressMapper;

    /**
     * 快递表分页查询
     * @param pageNum
     * @param pageSize
     * @param express
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PageInfo findPage(int pageNum, int pageSize, Express express) {
        if(ObjectUtil.isNull(express)){
            express = new Express();
        }

        // 分页
        PageHelper.startPage(pageNum,pageSize);
        List<Express> expressList = expressMapper.select(express);
        return new PageInfo(expressList);
    }

    /**
     * 根据主键查询快递表
     * @param expressId
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public Express findById(Serializable expressId) {
        return expressMapper.selectById(expressId);
    }

    /**
     * 快递表新增
     * @param express
     */
    @Override
    public void add(Express express) {
        expressMapper.insert(express);
    }

    /**
     * 修改快递表
     * @param express
     */
    @Override
    public void modify(Express express) {
        expressMapper.update(express);
    }

    /**
     * 根据主键删除快递表
     * @param expressId
     */
    @Override
    public void removeById(Serializable expressId) {
        if(((String)expressId).contains(",")){
            expressMapper.deleteByIds(((String)expressId).split(","));
        }else {
            expressMapper.deleteById(expressId);
        }
    }
}
